#ifndef VSGEOMETRYNODE_H
#define VSGEOMETRYNODE_H
#include "VSNode.h"
#include "VSMorphSet.h"
#include "VSGeometry.h"
namespace VSEngine2
{
	class VSStream;
	class VSGRAPHIC_API VSGeometryNode : public VSNode
	{
		//PRIORITY
		
		//RTTI
		DECLARE_RTTI;
		DECLARE_INITIAL
	public:
		VSGeometryNode();
		virtual ~VSGeometryNode();
		virtual unsigned int GetST(){return ST_GEOMETRY_NODE;}
		inline void SetMorphSet(VSMorphSet * pMorphSet)
		{
			if (!pMorphSet)
			{
				m_pMorphSet = NULL;
				return ;
			}
			else
			{
				if (GetNodeNum() != pMorphSet->GetBufferNum())
				{
					return;
				}
				for (unsigned int i = 0 ; i < pMorphSet->GetMorphNum() ; i++)
				{
					for (unsigned int j = 0 ; j < pMorphSet->GetBufferNum(); j++)
					{
						unsigned int VertexNum = pMorphSet->GetMorph(i)->GetVertexNum(j);
						VSGeometry * pGeometry = (VSGeometry *)GetChild(j);
						if (VertexNum && pGeometry)
						{
							if (VertexNum != pGeometry->GetVertexNum())
							{
								return ;
							}

						}
					}
					
				}
			
			}
			m_pMorphSet = pMorphSet;
		}
		inline const VSMorphSet *GetMorphSet()const
		{
			return m_pMorphSet;
		}
		VSGeometry * GetGeometry(unsigned int i);
	public:

		
		virtual unsigned int DiskUse()const;

		virtual bool Save(VSStream & rStream,unsigned int &iSaveUse)const;
		virtual bool Load(VSStream & rStream,unsigned int &iSaveUse);
		virtual bool Link(VSStream & rStream);

		virtual bool Register(VSStream & rStream)const;
	public:
		virtual bool Clone(const VSObject *pObject,unsigned int uiType);
	protected:
		VSMorphSetPtr m_pMorphSet;
	};
	DECLARE_Ptr(VSGeometryNode);
	VSTYPE_MARCO(VSGeometryNode);
}
#endif